home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / glibc108.gz / glibc108 / glibc-1.08.1 / sysdeps / mach / hurd / i386 / __sigret.c next >
Encoding:
C/C++ Source or Header  |  1994-05-01  |  2.7 KB  |  83 lines

  1. /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <hurd.h>
  20. #include <hurd/signal.h>
  21. #include <hurd/threadvar.h>
  22.  
  23. int
  24. __sigreturn (register const struct sigcontext *scp)
  25. {
  26.   struct hurd_sigstate *ss;
  27.   register int *usp asm ("%eax"); /* Force it into a register.  */
  28.   mach_port_t *reply_port;
  29.  
  30.   if (scp == NULL)
  31.     {
  32.       errno = EINVAL;
  33.       return -1;
  34.     }
  35.  
  36.   ss = _hurd_self_sigstate ();
  37.   ss->blocked = scp->sc_mask;
  38.   ss->intr_port = scp->sc_intr_port;
  39.   if (scp->sc_onstack)
  40.     ss->sigaltstack.ss_flags &= ~SA_ONSTACK; /* XXX threadvars */
  41.   __mutex_unlock (&ss->lock);
  42.  
  43.   /* Destroy the MiG reply port used by the signal handler, and restore the
  44.      reply port in use by the thread when interrupted.  */
  45.   reply_port =
  46.     (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY);
  47.   if (*reply_port)
  48.     __mach_port_destroy (__mach_task_self (), *reply_port);
  49.   *reply_port = scp->sc_reply_port;
  50.  
  51.   /* Push the flags and registers onto the stack we're returning to.  */
  52.   usp = (int *) scp->sc_uesp;
  53.  
  54.   /* The last thing popped will be the PC being restored, so push it first.  */
  55.   *--usp = scp->sc_eip;
  56.   *--usp = scp->sc_efl;        /* Second to last, processor flags.  */
  57.  
  58.   /* Segment registers??? XXX */
  59.  
  60.   /* Now push the general registers in the reverse of the order they will
  61.      be popped off by the `popa' instruction.  The instruction passes over
  62.      a word corresponding to %esp, but does not use the value.  */
  63.   *--usp = scp->sc_eax;
  64.   *--usp = scp->sc_ecx;
  65.   *--usp = scp->sc_edx;
  66.   *--usp = scp->sc_ebx;
  67.   *--usp = 0;            /* Ignored by `popa'.  */
  68.   *--usp = scp->sc_ebp;
  69.   *--usp = scp->sc_esi;
  70.   *--usp = scp->sc_edi;
  71.  
  72.   asm volatile
  73.     ("movl %0, %%esp\n"        /* Switch to the target stack.  */
  74.      "popa\n"            /* Pop all the general registers.  */
  75.      "popf\n"            /* Pop the flags.  */
  76.      "ret\n"            /* Pop the target PC and jump to it.  */
  77.      "hlt" : :            /* Firewall.  */
  78.      "g" (usp));
  79.  
  80.   /* NOTREACHED */
  81.   return -1;
  82. }
  83.